package com.test.controller;
import java.util.Date;

import com.test.entity.User;
import com.test.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @GetMapping("/user/{id}")
    User getUserById(@PathVariable Integer id){
        return userMapper.getById(id);
    }

    @GetMapping("/user/{username}/{nickname}")
    public String insertUser(@PathVariable("username") String username, @PathVariable("nickname") String nickname){
        User user = new User();
        user.setId(0);
        user.setUsername(username);
        user.setNickname(nickname);
        user.setBirthday(new Date());
        userMapper.insertUser(user);
        log.info("@@@" + new Date());
        return "success";
    }
}
